<!--
 * @Author: your name
 * @Date: 2020-12-17 09:04:18
 * @LastEditTime: 2020-12-25 16:18:50
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \solaxcloud\src\views\alarm\alarmTypeDefine\import.vue
-->
<template>
    <div>
        <el-dialog
            :title="$t('alarmpush.addAlarmType.title')"
            :visible="visibleShow"
            class="el-dialog-sm"
            @opened="()=>{form.deviceType=deviceType}"
            @close="()=>{$store.commit('setVisibleShow',false)}">
            <el-form ref="form" :model="form" label-width="200px" >
                <el-row :gutter="24">
                    <el-col :span="20">
                        <el-form-item :label="$t('equipmentType')" prop="deviceType" :rules="[{ required: true, message: $t('pleaseSelect')}]">
                            <el-select v-model="form.deviceType" filterable :placeholder="$t('pleaseSelect')">
                                <el-option
                                v-for="item in deviceTypeData"
                                :key="item.value"
                                :label="item.code"
                                :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item :label="$t('version.versionService.fileURL')" prop="excelFile" :rules="[{ required: true, message: $t('pleaseSelect')}]">
                            <baseFile v-model="form.excelFile"></baseFile>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="()=>{$store.commit('setVisibleShow',false)}">{{$t('cancel')}}</el-button>
                <el-button type="primary" @click="save('form')">{{$t('save')}}</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import baseFile from '../../../components/common/baseFileInput'
export default {
    components:{
        baseFile
    },
    props: {
        deviceType:'',
        deviceTypeData:''
    },
    data() {
        return {
            form:{
                deviceType:'',
                excelFile:''
            }
        };
    },
    computed: {
        visibleShow(){
            return this.$store.state.sysStore.visibleShow
        }
    },
    mounted(){

    },
    methods: {
        save(formName){
            this.$refs[formName].validate(async (valid) => {
              if (valid) {
                  this.commitForm()
              } else {
                console.log('error submit!!');
                return false;
              }
            });
        },
        async commitForm(){
            let data = await this.API.importAlarmDefine(this.form)
            if(data === '1'){
                this.$message.error(this.$t('version.versionAdd.formatError'))
            }else if(data === '2'){
                this.$message.error(this.$t('index_js_notNull'))
            }else if(data === '3'){
                this.$message.error(this.$t('alarmpush.mysqlError'))
            }else if(data === '0'){
                this.$message.success(this.$t('index.control_success'))
                this.$emit('uploadData')
                this.$store.commit('setVisibleShow',false)
            }
        }
    }
};
</script>

<style lang="less">
.el-input-number.is-controls-right .el-input__inner{
    text-align: left;
}
</style>
